import logging

from seed_data.api import TabLeOperator
from seed_data.table import ServerCfg

LOG = logging.getLogger()


def add_config(config):
    find_order = {'key': config['key']}
    order_list = TabLeOperator(ServerCfg).get(find_order)
    if order_list:
        LOG.warning('config key {} have added'.format(config['key']))
    else:
        TabLeOperator(ServerCfg).add(config)

#
# def set_ship_flag(order_number):
#     find_order = {'bmc': order_number}
#     order_list = TabLeOperator(Hardware).get(find_order)
#     if order_list:
#         update_order = {'bmc': order_number, 'ssh_user': True}
#         TabLeOperator(Hardware).update(update_order)
#     else:
#         err_msg = "not find order_number {}, can't ship".format(order_number)
#         LOG.error(err_msg)
#         raise Exception(err_msg)
#
#
# def set_ship_text_flag(order_number):
#     find_order = {'order_number': order_number}
#     order_list = TabLeOperator(Hardware).get(find_order)
#     if order_list:
#         update_order = {'order_number': order_number, 'ship_text': True}
#         TabLeOperator(Hardware).update(update_order)
#     else:
#         err_msg = "not find order_number {}, can't ship".format(order_number)
#         LOG.error(err_msg)
#         raise Exception(err_msg)


if __name__ == '__main__':
    server_cfg = {'bmc':'10.228.5.28',}
    add_config(server_cfg)
    # filter_dict = {'key': '1212096865390528788'}
    # p = TabLeOperator(ServerCfg).get(filter_dict)
    # print(p)
